using System;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;
using SerialTool.Models; 

namespace SerialTool.Converters;

public class DirectionToBrushConverter : IValueConverter
{
    // 定义颜色属性，方便在 XAML 中覆盖（如果需要）
    public IBrush SentBrush { get; set; } = Brushes.Blue;
    public IBrush ReceivedBrush { get; set; } = Brushes.Green;
    public IBrush DefaultBrush { get; set; } = Brushes.Black; // 默认颜色

    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is LogMessageDirection direction)
        {
            return direction == LogMessageDirection.Sent ? SentBrush : ReceivedBrush;
        }
        return DefaultBrush;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
} 